//
// Created by Dell on 2021/9/22.
//

#include "node.h"

node::node() {
    // 设置目标矩阵
    target[0][0] = 1;
    target[0][1] = 2;
    target[0][2] = 3;
    target[1][2] = 4;
    target[2][2] = 5;
    target[2][1] = 6;
    target[2][0] = 7;
    target[1][0] = 8;
    target[1][1] = 0;
}

node::node(node *tem) {
    this->number = tem->number;
    // 设置目标矩阵
    target[0][0] = 1;
    target[0][1] = 2;
    target[0][2] = 3;
    target[1][2] = 4;
    target[2][2] = 5;
    target[2][1] = 6;
    target[2][0] = 7;
    target[1][0] = 8;
    target[1][1] = 0;
}

node::~node() {

}

/**
 * 计算H函数
 * @return
 */
int node::countH() {
    int tem = 0;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (this->number[i][j] != this->target[i][j]) {
                ++tem;
            }
        }
    }
    return tem;
}

/**
 * 判断是否完成
 * @return
 */
bool node::check() {
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            if (this->number[i][j] != this->target[i][j]) {
                return false;
            }
        }
    }
    return true;
}

/**
 * 得到number数组中的一个数
 * @param x
 * @param y
 * @return
 */
int node::getNumber(int x, int y) {
    return number[x][y];
}

/**
 * 得到number数组
 * @return
 */
vector<vector<int>> node::getNumber() {
    return this->number;
}

/**
 * 设置number矩阵
 * @param x
 * @param y
 * @param tem
 */
void node::setNumber(int x, int y, int tem) {
    number[x][y] = tem;
    return;
}

/**
 * 交换number的两个点
 * @param x1
 * @param y1
 * @param x2
 * @param y2
 */
void node::swapNumber(int x1, int y1, int x2, int y2) {
    int tem = number[x1][y1];
    number[x1][y1] = number[x2][y2];
    number[x2][y2] = tem;
    return;
}

/**
 * 设置X和Y
 * @param x
 * @param y
 */
void node::setXAndY(int x, int y) {
    startX = x;
    startY = y;

    return;
}

/**
 * 设置G和H
 * @param g
 * @param h
 */
void node::setGAndH(int g, int h) {
    this->g = g;
    this->h = h;
    return;
}

/**
 * 得到X
 * @return
 */
int node::getX() {
    return startX;
}

/**
 * 得到Y
 * @return
 */
int node::getY() {
    return startY;
}